﻿using Iot.AspNetCore;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TomNet.AspNetCore.Mvc;
using TomNet.Demo.Entity.Dto;

namespace TomNet.Demo.Web.Controllers
{
    public class UpLoadController : ApiControllerBase
    {
        private readonly IServiceProvider _provider;
        private readonly UploadHelper _uploadHelper;
        public UpLoadController(
            IServiceProvider provider,
            UploadHelper uploadHelper)
        {
            _provider = provider;
            _uploadHelper = uploadHelper;
        }


        /// <summary>
        /// 上传图片
        /// </summary>
        [HttpPost("UploadImage")]
        public async Task<IActionResult> UploadImage([FromForm] UploadDto uploadImage)
        {
            var options = _provider.GetTomNetOptions().UploadPolicies["images"];
            var res = await _uploadHelper.UploadAsync(uploadImage.File, options,"tom");
            return Ok(res);
        }
    }
}
